package tiedotdb

import (
	"github.com/HouzuoGuo/tiedot/db"
	"github.com/astaxie/beego"
	"math/rand"
	"time"
)

func init() {
	rand.Seed(time.Now().UTC().UnixNano())
}

func Insert(tableName string, doc map[string]interface{}) (id int, err error) {
	dir := beego.AppConfig.String("tiedotdic")
	tiedb, err := db.OpenDB(dir)
	if err != nil {
		panic(err)
	}
	dbExcute := tiedb.Use(tableName)
	return dbExcute.Insert(doc)
	defer tiedb.Close()
	return
}

func Delete(tableName string, id int64) error {

	return nil
}

func Update(tableName string) {

}

func Query(q map[string]interface{}) {

}

func CreateTable(tableName string) {
	dir := beego.AppConfig.String("tiedotdic")
	tiedb, err := db.OpenDB(dir)
	if err != nil {
		panic(err)
	}
	err = tiedb.Create(tableName)
	if err != nil {
		panic(err)
	}
	defer tiedb.Close()
}
